package com.leyou.item.client;

import com.leyou.common.dto.PageDTO;
import com.leyou.item.dto.*;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author 虎哥
 */
@FeignClient("item-service")
public interface ItemClient {
    @GetMapping("/spu/{id}")
    SpuDTO querySpuById(@PathVariable("id") Long id);

    @GetMapping("/brand/{id}")
    BrandDTO queryBrandById(@PathVariable("id") Long id);

    @GetMapping("/spec/list")
    List<SpecGroupDTO> querySpecs(@RequestParam("id") Long categoryId);

    @GetMapping("/sku/of/spu")
    List<SkuDTO> querySkuBySpuId(@RequestParam("id") Long spuId);

    @GetMapping("/spu/detail")
    SpuDetailDTO queryDetailBySpuId(@RequestParam("id") Long spuId);

    @GetMapping("/spu/page")
    PageDTO<SpuDTO> querySpuByPage(
            @RequestParam(value = "page", defaultValue = "1") Integer page,
            @RequestParam(value = "rows", defaultValue = "5") Integer rows,
            @RequestParam(value = "saleable", required = false) Boolean saleable,
            @RequestParam(value = "categoryId", required = false) Long categoryId,
            @RequestParam(value = "brandId", required = false) Long brandId,
            @RequestParam(value = "id", required = false) Long id
    );

    @GetMapping("/spec/params")
    List<SpecParamDTO> queryParams(
            @RequestParam(value = "gid", required = false) Long gid,
            @RequestParam(value = "cid", required = false) Long cid,
            @RequestParam(value = "searching", required = false) Boolean searching
    );

    @GetMapping("/brand/list")
    List<BrandDTO> queryBrandByIds(@RequestParam("ids") List<Long> ids);

    @GetMapping("/category/list")
    List<CategoryDTO> queryCategoryByIds(@RequestParam("ids") List<Long> ids);

    /**
     * 根据id批量查询sku
     * @param ids sku的id集合
     * @return sku集合
     */
    @GetMapping("/sku/list")
    List<SkuDTO> querySkuByIds(@RequestParam("ids") List<Long> ids);

    /**
     * 批量减库存
     * @param skuMap sku及num的map
     */
    @PutMapping("/stock/minus")
    void minusStock(@RequestBody Map<Long, Integer> skuMap);

    /**
     * 批量恢复库存
     * @param skuMap sku及num的map
     */
    @PutMapping("/stock/plus")
    void plusStock(@RequestBody Map<Long, Integer> skuMap);
}
